home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / amiga.programming / comp.sys.amiga.programmer_7057_000037.msg < prev    next >
Encoding:
Text File  |  1994-11-27  |  2.1 KB  |  57 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: dd.chalmers.se!news.chalmers.se!sunic!EU.net!sun4nl!sci.kun.nl!polder!rhialto
  3. From: rhialto@polder.ubc.kun.nl (Olaf Seibert)
  4. Subject: Re: Using Message Ports in C, and in Pascal...
  5. Message-ID: <rhialto.763123144@polder.ubc.kun.nl>
  6. Sender: news@sci.kun.nl (News owner)
  7. Nntp-Posting-Host: polder.ubc.kun.nl
  8. Organisation: Polderland Language & Speech Technology
  9. Organization: University of Nijmegen, The Netherlands
  10. References: <2klupi$3h5@canopus.cc.umanitoba.ca> <k+Mqu*7tc@peti.GUN.de>
  11. Date: Tue, 8 Mar 1994 10:39:04 GMT
  12. Lines: 43
  13.  
  14. In <k+Mqu*7tc@peti.GUN.de> simons@peti.GUN.de (Peter Simons) writes:
  15. >The reason is that PutMsg() and other routines exptect a pointer to a
  16. >'Message' structure as parameter, which is just the node header to
  17. >chain them in a list, a pointer to the reply port and the length of
  18. >the message. Obviously, the length specifies how many byte of actual
  19. >data are appended. Now, most programmer define their own structure
  20. >which is a usual 'Message' plus the to-be-sent data and send this
  21. >structure off.
  22. >
  23. >You do not really need to typecast the structure, but otherwise your
  24. >compiler would complain because he expects a pointer to 'Message' and
  25. >not to 'whateverMessage'. In fact, it doesn't make a difference for
  26. >the routine it's just common practise to cast in such situations.
  27.  
  28. In fact, there is a slightly different solution, that is on average
  29. about the same amount of typing, but somewhat cleaner.
  30.  
  31. Suppose you have
  32.  
  33. struct MyMsg {
  34.     struct Message msg;
  35.     int data;
  36. } *mymsg;
  37.  
  38. and you want to PutMsg() it. Now you could do
  39.  
  40.     PutMsg((struct Message *)mymsg, ...);
  41.  
  42. but also
  43.  
  44.     PutMsg(&mymsg->msg, ...);
  45.  
  46. This lets the compiler check the types better, because there is no
  47. cast. This solution works for almost all AmigaOS structures; the
  48. most annoying ones that don't work are MinList vs. List and MinNode
  49. vs. Node. These are interchangable for most List manipulating functions,
  50. yet the types are different.
  51.  
  52. >        bye, Peter
  53. -Olaf.
  54. --
  55. ___ Olaf 'Rhialto' Seibert      D787B44DFC896063 4CBB95A5BD1DAA96 
  56. \X/ There are no lemurs in this post    rhialto@polder.ubc.kun.nl
  57.